﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using ServerApplication;
using Lists;
namespace Sim
{
    public class MyThreadPool
    {
        private IList<Thread> _threads;

        public MyThreadPool()
        {
            _threads = new List<Thread>();
        }

        public void LaunchThread(string tournamentName)
        {
            for (int i = 0; i < TournamentList.tournamentList.Count; i++)
            {
                if (TournamentList.tournamentList[i].title == tournamentName)
                {

                    Thread thread = new Thread(Program.sa.checkNextRound);
                    thread.IsBackground = true;
                    thread.Name = string.Format("Thread" + TournamentList.tournamentList[i].title);

                    _threads.Add(thread);
                    thread.Start(TournamentList.tournamentList[i].title);
                    break;
                }
            }
        }

        public void KillThread(string tournamentName)
        {
            string id = string.Format("Thread" + tournamentName);
            foreach (Thread thread in _threads)
            {
                if (thread.Name == id)
                    thread.Abort();
            }
        }
    }
}
